package com.yaosheng.thread.lock;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * Created by yaosheng on 2021/6/30.
 * CyclicBarrier:满足第一个参数的条件，执行第二个参数的内容
 */
public class TestCyclicBarrier {

    public static void main(String[] args) {

        // CyclicBarrier barrier = new CyclicBarrier (20,() -> System.out.println ("满人，出发"));
        CyclicBarrier cyclicBarrier = new CyclicBarrier (20, new Runnable () {
            public void run() {
                System.out.println ("满人，出发");
            }
        });

        for(int i=0;i<100;i++){

            new Thread (() ->{
                try{
                    cyclicBarrier.await ();
                }catch (InterruptedException e){
                    e.printStackTrace ();
                }catch (BrokenBarrierException e){
                    e.printStackTrace ();
                }
            }).start ();

        }
    }

}
